import React from "react";
import { Text, Navigator } from "react-native";

import BackAndroid from "BackAndroid";
import Platform from "Platform";

import Config from "../config";
import Constants from "../common/Constants";
import ToastUtils from "../common/ToastUtils";
import { ObjUtils } from "../utils/Utils";

import BasePage from "../pages/common/BasePage";
import CommonCommentListPage from "../pages/common/CommonCommentListPage";
import CommonInputPage from "../pages/common/CommonInputPage";
import WebViewPage from "../pages/common/WebViewPage";
import AdWebViewPage from "../pages/common/AdWebViewPage";

import WelcomePage from "../pages/login/WelcomePage";
import LoginAdvertPage from "../pages/login/LoginAdvertPage";
import LoginPage from "../pages/login/LoginPage";
import BindPage from "../pages/login/BindPage";
import LoginPhonePage from "../pages/login/LoginPhonePage";
import LoginRegistePage from "../pages/login/LoginRegistePage";
import LoginProvisionPage from "../pages/login/LoginProvisionPage";

import HomePage from "../pages/home/HomePage";
import MainSearchView from "../pages/home/MainSearchView";
import PlateSearchPage from "../pages/home/PlateSearchPage";
import SearchListView from "../pages/home/SearchListView";
import GongGaoListView from "../pages/home/GongGaoListView";

import HeartMainPage from "../pages/heart/HeartMainPage";
import RiliPage from "../pages/home/RiliPage";

import WH_ChuangxinWeb from "../pages/workhard/WH_ChuangxinWeb";
import WorkHardPage from "../pages/workhard/WorkHardPage";
import WH_WritePage from "../pages/workhard/WH_WritePage";
import WH_PostContentPage from "../pages/workhard/WH_PostContentPage";
import WH_TypeShowPage from "../pages/workhard/WH_TypeShowPage";
import WH_CYSPage from "../pages/workhard/WH_CYSPage";
import WH_WXTWPage from "../pages/workhard/WH_WXTWPage";
import WH_SearchPage from "../pages/workhard/WH_SearchPage";
import WH_JindianziMainView from "../pages/workhard/WH_JindianziMainView";
import WH_JDZRankView from "../pages/workhard/WH_JDZRankView";
import WH_AallTypePage from "../pages/workhard/WH_AallTypePage";
import WH_WinnerPage from "../pages/workhard/WH_WinnerPage";
import WH_ZhinanPage from "../pages/workhard/WH_ZhinanPage";
import WH_HuojiangListView from "../pages/workhard/WH_HuojiangListView";
import WH_GongjiangPage from "../pages/workhard/WH_GongjiangPage";
import WH_ZhuanjiaPage from "../pages/workhard/WH_ZhuanjiaPage";
import WH_HuiYinBiPage from "../pages/workhard/WH_HuiYinBiPage";
import WH_ZhuanjiaListPage from "../pages/workhard/WH_ZhuanjiaListPage";

import ActivityApplicantPage from "../pages/activity/ActivityApplicantPage";
import ActivityMainPage from "../pages/activity/ActivityMainPage";
import ActivityContentPage from "../pages/activity/ActivityContentPage";
import ActivityEnterSingerPage from "../pages/activity/ActivityEnterSingerPage";
import ActivityEnterSingerDeclarationPage from "../pages/activity/ActivityEnterSingerDeclarationPage";
import ActivitySingerListPage from "../pages/activity/ActivitySingerListPage";
import ActivitySingerDataPage from "../pages/activity/ActivitySingerDataPage";
import ActivityMapPage from "../pages/activity/ActivityMapPage";
import ActivityMuduPage from "../pages/activity/ActivityMuduPage";
import ActivityUserListView from "../pages/activity/ActivityUserListView";

import UserDianzanPage from "../pages/user/UserDianzanPage";
import UserShoucangPage from "../pages/user/UserShoucangPage";
import UserBaomingPage from "../pages/user/UserBaomingPage";
import UserFabuPage from "../pages/user/UserFabuPage";
import UserShezhiPage from "../pages/user/UserShezhiPage";
import UserAboutPage from "../pages/user/UserAboutPage";
import UserTuiSongPage from "../pages/user/UserTuiSongPage";
import UserZiliaoPage from "../pages/user/UserZiliaoPage";
import UserRenzhengPage from "../pages/user/UserRenzhengPage";
import UserNickNamePage from "../pages/user/UserNickNamePage";
import UserEmailPage from "../pages/user/UserEmailPage";
import UserDepartmentPage from "../pages/user/UserDepartmentPage";
import UserSectionPage from "../pages/user/UserSectionPage";
import UserPasswordPage from "../pages/user/UserPasswordPage";
import UserContactUsPage from "../pages/user/UserContactUsPage";
import UserForgetPwdPage from "../pages/user/UserForgetPwdPage";
import UserNoticePage from "../pages/user/UserNoticePage";
import UserNoticeChatPage from "../pages/user/UserNoticeChatPage";
import UserManagerChatPage from "../pages/user/UserManagerChatPage";

import NewsContentPage from "../pages/news/NewsContentPage";
import NewsTopicsPage from "../pages/news/NewsTopicsPage";

import AudioTestPage from "../pages/test/AudioTestPage";

import HeartEnterWorldPage from "../pages/heart/HeartEnterWorldPage";
import HeartEAPMainPage from "../pages/heart/HeartEAPMainPage";
import HeartEapListPageNew from "../pages/heart/HeartEapListPageNew";
import HeartEapOnlinePage from "../pages/heart/HeartEapOnlinePage";
import HeartEapListPageReview from "../pages/heart/HeartEapListPageReview";
import HeartEapContentPage from "../pages/heart/HeartEapContentPage";
import HeartWorryPage from "../pages/heart/HeartWorryPage";
import HeartJobPage from "../pages/heart/HeartJobPage";
import HeartLovePage from "../pages/heart/HeartLovePage";
import HeartLoveDeletePage from "../pages/heart/HeartLoveDeletePage";
import HeartLoveListPage from "../pages/heart/HeartLoveListPage";
import HeartConsultPage from "../pages/heart/HeartConsultPage";
import HeartConsultListPage from "../pages/heart/HeartConsultListPage";
import HeartExpertDataPage from "../pages/heart/HeartExpertDataPage";
import HeartLoveSearchResultPage from "../pages/heart/HeartLoveSearchResultPage";
import HeartLoveSearchConditionPage from "../pages/heart/HeartLoveSearchConditionPage";
import HeartLoveSearchNickPage from "../pages/heart/HeartLoveSearchNickPage";
import HeartLoveSearchMainPage from "../pages/heart/HeartLoveSearchMainPage";
import HeartLoveFindYouPage from "../pages/heart/HeartLoveFindYouPage";
import HeartLovePhotoPage from "../pages/heart/HeartLovePhotoPage";
import HeartLoveOtherDataPage from "../pages/heart/HeartLoveOtherDataPage";
import HeartLoveCommonDataEditPage from "../pages/heart/HeartLoveCommonDataEditPage";
import HeartLoveHeAndShePage from "../pages/heart/HeartLoveHeAndShePage";
import HeartLoveTagEditPage from "../pages/heart/HeartLoveTagEditPage";
import HeartLoveChatPage from "../pages/heart/HeartLoveChatPage";
import HeartLoveQuestionPage from "../pages/heart/HeartLoveQuestionPage";
import HeartLoveQuestionContentPage from "../pages/heart/HeartLoveQuestionContentPage";
import HeartLoveQuestionAskPage from "../pages/heart/HeartLoveQuestionAskPage";
import HeartVolunteerPage from "../pages/heart/HeartVolunteerPage";
import HeartVolunteerAgreementPage from "../pages/heart/HeartVolunteerAgreementPage";
import HeartVolunteerSubmitPage from "../pages/heart/HeartVolunteerSubmitPage";
import HeartBeginTestPage from "../pages/heart/HeartBeginTestPage";
import HeartTestMainPage from "../pages/heart/HeartTestMainPage";
import HeartSecretMsgPage from "../pages/heart/HeartSecretMsgPage";
import HeartZJListPage from "../pages/heart/HeartZJListPage";
import HeartMsgListPage from "../pages/heart/HeartMsgListPage";
import HeartSecretMsgContentPage from "../pages/heart/HeartSecretMsgContentPage";
import HeartSecretChatPage from "../pages/heart/HeartSecretChatPage";
import HeartEndListContentPage from "../pages/heart/HeartEndListContentPage";
import HeartTestWebPage from "../pages/heart/HeartTestWebPage";

import VipsercardContentPage from "../pages/vipsercard/VipsercardContentPage";
import VipActivityPage from "../pages/vipsercard/VipActivityPage";

// import VipOpenCardPage from '../pages/vipsercard/VipOpenCardPage';
import VipOpenCardWebViewPage from "../pages/vipsercard/VipOpenCardWebViewPage";
import VipActivityContentPage from "../pages/vipsercard/VipActivityContentPage";
import VipFeedback from "../pages/vipsercard/VipFeedback";
import VipSuggest from "../pages/vipsercard/VipSuggest";
import VipActivityXianshiPage from "../pages/vipsercard/VipActivityXianshiPage";
import VipHaveQuestPage from "../pages/vipsercard/VipHaveQuestPage";
import VipHaveQuestionContentPage from "../pages/vipsercard/VipHaveQuestionContentPage";

import SportMainPage from "../pages/sport/SportMainPage";
import SportUserListPage from "../pages/sport/SportUserListPage";
import SportDibiaoWelcomePage from "../pages/sport/SportDibiaoWelcomePage";
import SportDibiaoMainPage from "../pages/sport/SportDibiaoMainPage";
import SportDibiaoDetailPage from "../pages/sport/SportDibiaoDetailPage";
import SportDataPage from "../pages/sport/SportDataPage";
import SportGonggaoPage from "../pages/sport/SportGonggaoPage";
import SportGonggaoContentPage from "../pages/sport/SportGonggaoContentPage";

import GuahaoMainPage from "../pages/guahao/GuahaoMainPage";
import GuahaoHospitalWebPage from "../pages/guahao/GuahaoHospitalWebPage";
import GuahaoHospitalListPage from "../pages/guahao/GuahaoHospitalListPage";
import GuahaoErweimaPage from "../pages/guahao/GuahaoErweimaPage";

import QuanziMainView from "../pages/home/QuanziMainView";
import QuanziMyPage from "../pages/quanzi/QuanziMyPage";
import QZ_writePage from "../pages/quanzi/QZ_writePage";
import QZ_WelcomeView from "../pages/quanzi/QZ_WelcomeView";
import QuanziPostContentPage from "../pages/quanzi/QuanziPostContentPage";
import QuanziContentPage from "../pages/quanzi/QuanziContentPage";
import QuanziQunDataPage from "../pages/quanzi/QuanziQunDataPage";
import QuanziAllListPage from "../pages/quanzi/QuanziAllListPage";
import QZ_SearchPage from "../pages/quanzi/QZ_SearchPage";
import QZ_QunliaoChatPage from "../pages/quanzi/QZ_QunliaoChatPage";
import QZ_QunliaoCreatePage from "../pages/quanzi/QZ_QunliaoCreatePage";
import QZ_ContentSearchPage from "../pages/quanzi/QZ_ContentSearchPage";
import QZ_QunliaoMemberListPage from "../pages/quanzi/QZ_QunliaoMemberListPage";
import QZ_MemberListPage from "../pages/quanzi/QZ_MemberListPage";
import QZ_QunliaoListPage from "../pages/quanzi/QZ_QunliaoListPage";
import QZ_CreatePage from "../pages/quanzi/QZ_CreatePage";
import QuanziFollowPage from '../pages/quanzi/QuanziFollowPage';
import QuanziReviewPage from '../pages/quanzi/QuanziReviewPage';
import QZ_FindListPage from '../pages/quanzi/QZ_FindListPage';
import QZ_FindOfMine from '../pages/quanzi/QZ_FindOfMine';

import ZHP_MainPage from "../pages/zahuopu/ZHP_MainPage";
import ZHP_WritePage from "../pages/zahuopu/ZHP_WritePage";
import ZHP_ContentPage from "../pages/zahuopu/ZHP_ContentPage";
import ZHP_ListPage from "../pages/zahuopu/ZHP_ListPage";
import ZHP_SearchPage from "../pages/zahuopu/ZHP_SearchPage";

import JifenMallPage from "../pages/jifenMall/JifenMallPage";
import JifenQiandaoPage from "../pages/jifenMall/JifenQiandaoPage";
import JifenLuckDrawPage from "../pages/jifenMall/JifenLuckDrawPage";
import JifenMyDuihuanPage from "../pages/jifenMall/JifenMyDuihuanPage";
import JifenMyChoujiangPage from "../pages/jifenMall/JifenMyChoujiangPage";
import JifenDuihuanPage from "../pages/jifenMall/JifenDuihuanPage";
import JifenDuihuanItemContentPage from "../pages/jifenMall/JifenDuihuanItemContentPage";
import JifenDuihuanResultPage from "../pages/jifenMall/JifenDuihuanResultPage";
import JifenChoujiangItemContentPage from "../pages/jifenMall/JifenChoujiangItemContentPage";
import JifenQiandaoGuiZe from "../pages/jifenMall/JifenQiandaoGuiZe";

import ShuwuMainPage from "../pages/shuwu/ShuwuMainPage";
import FeedbackCommentPage from "../pages/jianyi/FeedbackCommentPage";

import UserPhonePage from "../pages/user/UserPhonePage";

let instance = null;
export class Routes {
  constructor() {
    if (!instance) {
      instance = this;
      this._pageIDQueue = [];
      this._navigator = null;
      this._currentPage = null;
      this._dataManager = null;
      this._firstClickBack = false;
      this._hasGoHome = false; //是否已进入过首页
      this._needGoNotificationAfterGoHome = false; //进入主页后是否需要跳转
      this._goNotificationDataSave = null;

      this._routeID = 1;
      // console.log("constructor Routes");
    }
  }

  setup(navigator, initPageData, dataManager) {
    this._navigator = navigator;
    this._dataManager = dataManager;
    this._pageIDQueue.push(initPageData);
    this._handlerBackButton = this._handlerBackButton.bind(this);
    BackAndroid.addEventListener("hardwareBackPress", this._handlerBackButton);
  }

  dispose() {
    BackAndroid.removeEventListener(
      "hardwareBackPress",
      this._handlerBackButton
    );
    this._pageIDQueue = null;
    this._navigator = null;
    instance = null;
  }

  getComponent(key) {
    var page = { component: null };
    switch (key) {
      case Config.pages.welcome.key:
        page.component = WelcomePage;
        break;
      case Config.pages.loginAdvertPage.key:
        page.component = LoginAdvertPage;
        break;
      case Config.pages.login.key:
        page.component = LoginPage;
        break;
      case Config.pages.bind.key:
        page.component = BindPage;
        break;
      case Config.pages.login_phone.key:
        page.component = LoginPhonePage;
        break;
      case Config.pages.login_register.key:
        page.component = LoginRegistePage;
        break;
      case Config.pages.login_provision.key:
        page.component = LoginProvisionPage;
        break;
      case Config.pages.home.key:
        page.component = HomePage;
        break;
      case Config.pages.home_search.key:
        page.component = MainSearchView;
        break;
      case Config.pages.plate_search.key:
        page.component = PlateSearchPage;
        break;
      case Config.pages.search_list.key:
        page.component = SearchListView;
        break;
      case Config.pages.gonggao_list.key:
        page.component = GongGaoListView;
        break;
      case Config.pages.chuangxin_web.key:
        page.component = WH_ChuangxinWeb;
        break;
      case Config.pages.rili.key:
        page.component = RiliPage;
        break;

      case Config.pages.workHard.key:
        page.component = WorkHardPage;
        break;
      case Config.pages.workHard_write.key:
        page.component = WH_WritePage;
        break;
      case Config.pages.wh_content.key:
        page.component = WH_PostContentPage;
        break;
      case Config.pages.wh_type_jdz.key:
      case Config.pages.wh_type_wxtw.key:
        page.component = WH_TypeShowPage;
        break;
      case Config.pages.wh_type_jdzbtn.key:
        page.component = WH_JindianziMainView;
        break;
      case Config.pages.wh_type_jdzrank.key:
        page.component = WH_JDZRankView;
        break;
      case Config.pages.workHard_alltype.key:
        page.component = WH_AallTypePage;
        break;
      case Config.pages.workHard_winner.key:
        page.component = WH_WinnerPage;
        break;
      case Config.pages.workHard_winnerlist.key:
        page.component = WH_HuojiangListView;
        break;
      case Config.pages.workHard_gongjiang.key:
        page.component = WH_GongjiangPage;
        break;
      case Config.pages.workHard_zhuanjia.key:
        page.component = WH_ZhuanjiaPage;
        break;
      case Config.pages.workHard_huiyinbi.key:
        page.component = WH_HuiYinBiPage;
        break;
      case Config.pages.workHard_zhinan.key:
        page.component = WH_ZhinanPage;
        break;
      case Config.pages.wh_type_cys.key:
        page.component = WH_CYSPage;
        break;
      case Config.pages.wh_zjtj_jdz.key:
        page.component = WH_ZhuanjiaListPage;
        break;
      case Config.pages.wh_search.key:
        page.component = WH_SearchPage;
        break;

      case Config.pages.activity_enter_auto.key:
        page.component = ActivityApplicantPage;
        break;
      case Config.pages.activity.key:
        page.component = ActivityMainPage;
        break;
      case Config.pages.activity_content.key:
        page.component = ActivityContentPage;
        break;
      case Config.pages.activity_userlist.key:
        page.component = ActivityUserListView;
        break;
      case Config.pages.activity_entrySinger.key:
        page.component = ActivityEnterSingerPage;
        break;
      case Config.pages.activity_entrySinger_text.key:
        page.component = ActivityEnterSingerDeclarationPage;
        break;
      case Config.pages.activity_singer_list.key:
        page.component = ActivitySingerListPage;
        break;
      case Config.pages.activity_singer.key:
        page.component = ActivitySingerDataPage;
        break;
      case Config.pages.activity_map.key:
        page.component = ActivityMapPage;
        break;
      case Config.pages.mudu_view.key:
        page.component = ActivityMuduPage;
        break;
      case Config.pages.audio_test.key:
        page.component = AudioTestPage;
        break;

      case Config.pages.user_dianzan.key:
        page.component = UserDianzanPage;
        break;
      case Config.pages.user_shoucang.key:
        page.component = UserShoucangPage;
        break;
      case Config.pages.user_baoming.key:
        page.component = UserBaomingPage;
        break;
      case Config.pages.user_fabu.key:
        page.component = UserFabuPage;
        break;
      case Config.pages.user_shezhi.key:
        page.component = UserShezhiPage;
        break;
      case Config.pages.user_about.key:
        page.component = UserAboutPage;
        break;
      case Config.pages.user_tsxx.key:
        page.component = UserTuiSongPage;
        break;
      case Config.pages.user_ziliao.key:
        page.component = UserZiliaoPage;
        break;
      case Config.pages.user_renzheng.key:
        page.component = UserRenzhengPage;
        break;
      case Config.pages.user_xgnc.key:
        page.component = UserNickNamePage;
        break;
      case Config.pages.user_xgemail.key:
        page.component = UserEmailPage;
        break;
      case Config.pages.user_xgdw.key:
        page.component = UserDepartmentPage;
        break;
      case Config.pages.user_xgbm.key:
        page.component = UserSectionPage;
        break;
      case Config.pages.user_xgmm.key:
        page.component = UserPasswordPage;
        break;
      case Config.pages.user_xgphone.key:
        page.component = UserPhonePage;
        break;

      case Config.pages.user_contact_us.key:
        page.component = UserContactUsPage;
        break;
      case Config.pages.user_forgetpwd.key:
        page.component = UserForgetPwdPage;
        break;
      case Config.pages.user_notice.key:
        page.component = UserNoticePage;
        break;
      case Config.pages.user_notice_chat.key:
        page.component = UserNoticeChatPage;
        break;
      case Config.pages.user_manager_chat.key:
        page.component = UserManagerChatPage;
        break;

      case Config.pages.common_comment.key:
        page.component = CommonCommentListPage;
        break;
      case Config.pages.common_input.key:
        page.component = CommonInputPage;
        break;
      case Config.pages.ad_Webview.key:
        page.component = AdWebViewPage;
        break;

      case Config.pages.news_content.key:
        page.component = NewsContentPage;
        break;
      case Config.pages.news_topics.key:
        page.component = NewsTopicsPage;
        break;

      // 心灵模仿
      // 心灵工坊
      case Config.pages.heart_main.key:
        page.component = HeartMainPage;
        break;
      case Config.pages.heart_enter_world.key:
        page.component = HeartEnterWorldPage;
        break;
      case Config.pages.heart_eap_list_new.key:
        page.component = HeartEapListPageNew;
        break;
      case Config.pages.heart_eap_list_review.key:
        page.component = HeartEapListPageReview;
        break;
      case Config.pages.heart_eap_main.key:
        page.component = HeartEAPMainPage;
        break;
      case Config.pages.heart_online.key:
        page.component = HeartEapOnlinePage;
        break;
      case Config.pages.heart_eap_content.key:
        page.component = HeartEapContentPage;
        break;
      case Config.pages.heart_worry.key:
        page.component = HeartWorryPage;
        break;
      case Config.pages.heart_job.key:
        page.component = HeartJobPage;
        break;
      case Config.pages.heart_love.key:
        page.component = HeartLovePage;
        break;
      case Config.pages.heart_love_delete.key:
        page.component = HeartLoveDeletePage;
        break;
      case Config.pages.heart_love_list.key:
        page.component = HeartLoveListPage;
        break;
      case Config.pages.heart_consult.key:
        page.component = HeartConsultPage;
        break;
      case Config.pages.heart_consult_list.key:
        page.component = HeartConsultListPage;
        break;
      case Config.pages.heart_expert_data.key:
        page.component = HeartExpertDataPage;
        break;
      case Config.pages.heart_love_search_condition.key:
        page.component = HeartLoveSearchConditionPage;
        break;
      case Config.pages.heart_love_search.key:
        page.component = HeartLoveSearchNickPage;
        break;
      case Config.pages.heart_love_search_main.key:
        page.component = HeartLoveSearchMainPage;
        break;
      case Config.pages.heart_love_search_result.key:
        page.component = HeartLoveSearchResultPage;
        break;
      case Config.pages.heart_love_find_you.key:
        page.component = HeartLoveFindYouPage;
        break;
        case Config.pages.heart_love_you_photo.key:
        page.component = HeartLovePhotoPage;
        break;
      case Config.pages.heart_love_other_data.key:
        page.component = HeartLoveOtherDataPage;
        break;
      case Config.pages.heart_love_contactData.key:
      case Config.pages.heart_love_baseData.key:
      case Config.pages.heart_love_littleData.key:
      case Config.pages.heart_love_familyData.key:
      case Config.pages.heart_love_lovePlanData.key:
        page.component = HeartLoveCommonDataEditPage;
        break;
      case Config.pages.heart_love_he_and_she.key:
        page.component = HeartLoveHeAndShePage;
        break;
      case Config.pages.heart_love_tag.key:
        page.component = HeartLoveTagEditPage;
        break;
      case Config.pages.heart_love_chat.key:
        page.component = HeartLoveChatPage;
        break;
      case Config.pages.heart_love_question.key:
        page.component = HeartLoveQuestionPage;
        break;
      case Config.pages.heart_love_question_content.key:
        page.component = HeartLoveQuestionContentPage;
        break;
      case Config.pages.heart_love_question_ask.key:
        page.component = HeartLoveQuestionAskPage;
        break;
      case Config.pages.heart_volunteer.key:
        page.component = HeartVolunteerPage;
        break;
      case Config.pages.heart_volunteer_agreement.key:
        page.component = HeartVolunteerAgreementPage;
        break;
      case Config.pages.heart_volunteer_submit.key:
        page.component = HeartVolunteerSubmitPage;
        break;
      case Config.pages.heart_begin_test.key:
        page.component = HeartBeginTestPage;
        break;
      case Config.pages.heart_test_main.key:
        page.component = HeartTestMainPage;
        break;
      case Config.pages.heart_common_web.key:
        page.component = WebViewPage;
        break;
      case Config.pages.post_common_web.key:
        page.component = WebViewPage;
        break;

      case Config.pages.heart_end_list_content_page.key:
        page.component = HeartEndListContentPage;
        break;
      case Config.pages.heart_test_web.key:
        page.component = HeartTestWebPage;
        break;

      case Config.pages.vipsercard_content.key:
        page.component = VipsercardContentPage;
        break;
      case Config.pages.vipactivitypage.key:
        page.component = VipActivityPage;
        break;
      case Config.pages.vipopencardpage.key:
        page.component = VipOpenCardWebViewPage;
        break;
      case Config.pages.vipfeedback.key:
        page.component = VipFeedback;
        break;
      case Config.pages.vipsuggest.key:
        page.component = VipSuggest;
        break;

      case Config.pages.sport_main.key:
        page.component = SportMainPage;
        break;
      case Config.pages.sport_user_list.key:
        page.component = SportUserListPage;
        break;
      case Config.pages.sport_dibiao_welcome.key:
        page.component = SportDibiaoWelcomePage;
        break;
      case Config.pages.sport_dibiao_main.key:
        page.component = SportDibiaoMainPage;
        break;
      case Config.pages.sport_dibiao_detail.key:
        page.component = SportDibiaoDetailPage;
        break;
      case Config.pages.sport_data.key:
        page.component = SportDataPage;
        break;
      case Config.pages.sport_gonggao.key:
        page.component = SportGonggaoPage;
        break;
      case Config.pages.sport_gonggao_content.key:
        page.component = SportGonggaoContentPage;
        break;
      case Config.pages.quanzi_review.key:
        page.component = QuanziReviewPage;
        break;
      case Config.pages.quanzi_findlist.key:
        page.component = QZ_FindListPage;
      break; 
      case Config.pages.quanzi_findmine.key:
        page.component = QZ_FindOfMine;
      break; 
      case Config.pages.quanzi_welcome.key:
        page.component = QZ_WelcomeView;
        break;
      case Config.pages.quanzi_post_content.key:
        page.component = QuanziPostContentPage;
        break;
      case Config.pages.quanzi_content.key:
        page.component = QuanziContentPage;
        break;
      case Config.pages.quanzi_main.key:
        page.component = QuanziMainView;
        break;
      case Config.pages.quanzi_my.key:
        page.component = QuanziMyPage;
        break;
      case Config.pages.quanzi_write.key:
        page.component = QZ_writePage;
        break;
      case Config.pages.quanzi_qun_data.key:
        page.component = QuanziQunDataPage;
        break;
      case Config.pages.quanzi_create.key:
        page.component = QZ_CreatePage;
        break;
      case Config.pages.quanzi_follow.key:
        page.component = QuanziFollowPage;
        break;
      case Config.pages.quanzi_all_list.key:
        page.component = QuanziAllListPage;
        break;
      case Config.pages.quanzi_search.key:
        page.component = QZ_SearchPage;
        break;
      case Config.pages.qz_qunliao_chat.key:
        page.component = QZ_QunliaoChatPage;
        break;
      case Config.pages.qz_qunliao_create.key:
        page.component = QZ_QunliaoCreatePage;
        break;

      case Config.pages.guahao_main.key:
        page.component = GuahaoMainPage;
        break;
      case Config.pages.guahao_hospital_web.key:
        page.component = GuahaoHospitalWebPage;
        break;
      case Config.pages.guahao_hospital_list.key:
        page.component = GuahaoHospitalListPage;
        break;
      case Config.pages.guahao_erweima.key:
        page.component = GuahaoErweimaPage;
        break;

      case Config.pages.vipactivitycontentpage.key:
        page.component = VipActivityContentPage;
        break;
      case Config.pages.qz_content_search.key:
        page.component = QZ_ContentSearchPage;
        break;
      case Config.pages.qz_qunliao_members.key:
        page.component = QZ_QunliaoMemberListPage;
        break;
      case Config.pages.quanzi_members.key:
        page.component = QZ_MemberListPage;
        break;
      case Config.pages.qz_qunliao_chats.key:
        page.component = QZ_QunliaoListPage;
        break;

      case Config.pages.zhp_main.key:
        page.component = ZHP_MainPage;
        break;
      case Config.pages.zhp_write.key:
        page.component = ZHP_WritePage;
        break;
      case Config.pages.zhp_content.key:
        page.component = ZHP_ContentPage;
        break;
      case Config.pages.zhp_search.key:
        page.component = ZHP_SearchPage;
        break;
      case Config.pages.zhp_list.key:
        page.component = ZHP_ListPage;
        break;
      case Config.pages.heart_Secret_msg_page.key:
        page.component = HeartSecretMsgPage;
        break;
      case Config.pages.heart_ZJ_List_page.key:
        page.component = HeartZJListPage;
        break;
      case Config.pages.heart_msg_list_page.key:
        page.component = HeartMsgListPage;
        break;
      case Config.pages.heart_Secret_msg_Content_page.key:
        page.component = HeartSecretMsgContentPage;
        break;
      case Config.pages.heart_secret_msg_chat.key:
        page.component = HeartSecretChatPage;
        break;
      case Config.pages.vipActivityXianshiPage.key:
        page.component = VipActivityXianshiPage;
        break;
      case Config.pages.vipquestpage.key:
        page.component = VipHaveQuestPage;
        break;
      case Config.pages.vipquestcontent.key:
        page.component = VipHaveQuestionContentPage;
        break;
      case Config.pages.jifenmall_main_page.key:
        page.component = JifenMallPage;
        break;
      case Config.pages.jifenmall_qiandaoguize.key:
        page.component = JifenQiandaoGuiZe;
        break;
      case Config.pages.jifenmall_qiandao_page.key:
        page.component = JifenQiandaoPage;
        break;
      case Config.pages.jifenmall_luckDraw_page.key:
        page.component = JifenLuckDrawPage;
        break;
      case Config.pages.jifenmall_my_duihuan.key:
        page.component = JifenMyDuihuanPage;
        break;
      case Config.pages.jifenmall_my_choujiang.key:
        page.component = JifenMyChoujiangPage;
        break;
      case Config.pages.jifenmall_duihuan.key:
        page.component = JifenDuihuanPage;
        break;
      case Config.pages.jifenmall_duihuan_item_content.key:
        page.component = JifenDuihuanItemContentPage;
        break;
      case Config.pages.jifenmall_duihuan_result.key:
        page.component = JifenDuihuanResultPage;
        break;
      case Config.pages.jifenmall_choujiang_item_content.key:
        page.component = JifenChoujiangItemContentPage;
        break;

      case Config.pages.shuwu_main.key:
        page.component = ShuwuMainPage;
        break;
      case Config.pages.jianyi_comment.key:
        page.component = FeedbackCommentPage;
        break;
    }
    return page;
  }

  _handlerBackButton() {
    if (Constants.stage.closeFullScreen()) {
      return true;
    }

    if (
      this._pageIDQueue.length > 0 &&
      this._currentPage != null &&
      this._currentPage.key != Config.pages.home.key
    ) {
      this.goBack();
      return true;
    }
    if (this._firstClickBack == false) {
      ToastUtils.show("如要退出程序请再次后退");
      this._firstClickBack = true;
      this._backTimer = setTimeout(() => {
        clearTimeout(this._backTimer);
        this._firstClickBack = false;
      }, 2000);
    } else {
      return false;
    }
    return true;
  }

  //外部调用使用jumpToPage
  _pushPage(nextPageData) {
    // console.log("pre page: ", prePageObj);
    // console.log(
    //   "go to page: " + nextPageData.key + "  ID:" + nextPageData.routeID,
    //   this._navigator
    // );
    // var nextComponent = this.getComponent(nextPageData.key);
    this._navigator.push({
      pageData: nextPageData,
      params: {
        pageData: nextPageData
      }
    });
  }

  goBack() {
    // console.log("goBack: ", this._navigator);
    if (
      this._currentPage == null ||
      this._currentPage.key == Config.pages.home.key
    ) {
      return;
    }
    // prePageObj.props.navigator.pop();
    if (this._pageIDQueue.length > 0) {
      this._pageIDQueue.pop();
      if (this._pageIDQueue.length > 0) {
        var pageData = this._pageIDQueue[this._pageIDQueue.length - 1];
        // if(pageData.key != Config.pages.login.key) {
        // this._navigator.jumpBack();
        this._jumpToPage(pageData, true);
        // }
      } else {
        this._jumpToPage(Config.pages.home, true);
      }
    }
  }

  goBackIndex(index) {
    // console.log("goBackIndex: ", this._navigator);
    if (
      this._currentPage == null ||
      this._currentPage.key == Config.pages.home.key
    ) {
      return;
    }

    if (this.popRoute(index)) {
      this.goBack();
    }
  }

  popRoute(index) {
    // console.log("popRoute: ", this._navigator);
    if (!index && this._pageIDQueue.length < index) {
      return false;
    }

    while (index > 0) {
      this._pageIDQueue.pop();
      index--;
    }

    return true;
  }

  jumpToPage(nextPageData, notSave = false) {
    // let currentPage = this._pageIDQueue.pop();
    // if(this._currentPage && this._currentPage.key == nextPageData.key &&
    //     this._currentPage.key != Config.pages.news_content && this._currentPage.key != Config.pages.wh_content) {
    //   console.log("Error:can not jump to self");
    //   return;
    // }
    // console.log(
    //   this._currentPage,
    //   " jump to page: ",
    //   nextPageData,
    //   this._navigator,
    //   notSave
    // );
    this._jumpToPage(nextPageData, false, notSave);
  }

  setCurrentPage(pageData) {
    this._currentPage = pageData;
    if (this._hasGoHome === false && pageData.key === Config.pages.home.key) {
      this._hasGoHome = true;
      // ToastUtils.show("setCurrentPage" + this._needGoNotificationAfterGoHome);
      if (this._needGoNotificationAfterGoHome === true) {
        setTimeout(() => {
          this.goNotification(this._goNotificationDataSave);
        }, 2000);
      }
    }
  }

  goNotification(data) {
    // ToastUtils.show("goNotification" + JSON.stringify(data) + JSON.stringify(this._currentPage));
    if (this._currentPage && this._hasGoHome === true) {
      // ToastUtils.show("goNotification11111" + JSON.stringify(data));
      this._currentPage.goNotification(data);
      this._needGoNotificationAfterGoHome = false;
      this._goNotificationDataSave = null;
    } else {
      this._needGoNotificationAfterGoHome = true;
      this._goNotificationDataSave = data;
      // ToastUtils.show("goNotification22222" + JSON.stringify(data));
    }
  }

  //isBack === false的时候，nextPageData传过来的是Config.pages里的值，不能直接使用，需要copy
  _jumpToPage(nextPageData, isBack, notSave) {
    var nextIndex = -1;
    const currentRoutes = this._navigator.getCurrentRoutes();
    if (isBack === true) {
      //向后跳的时候，先拿到需要跳到的Route的id，nextPageData不需要copy，直接用
      currentRoutes.some((item, index) => {
        if (item.pageData.routeID === nextPageData.routeID) {
          nextIndex = index;
          return;
        }
      });
    } else {
      //向前跳：新闻跳新闻的时候，要新建route，不能用以前的
      if (
        this._currentPage &&
        this._currentPage.key === Config.pages.news_content.key &&
        this._currentPage.key === nextPageData.key
      ) {
        nextPageData = this._copyPageData(nextPageData);
        nextPageData.routeID = ++this._routeID;
      } else {
        //向前跳的其他情况，判断是否以前存在同样key的route
        currentRoutes.some((item, index) => {
          if (item.pageData.key === nextPageData.key) {
            nextIndex = index;
            return;
          }
        });
        //假如存在，则用nextPageData 的 routeData
        if (nextIndex > -1) {
          currentRoutes[nextIndex].pageData.routeData = nextPageData.routeData;
          nextPageData = currentRoutes[nextIndex].pageData;
        } else {
          nextPageData = this._copyPageData(nextPageData);
          nextPageData.routeID = ++this._routeID;
        }
      }

      //是否需要保存在队列里面
      if (notSave === false) {
        this._pageIDQueue.push(nextPageData);
      }
    }
    //退出以前Routes
    if (
      this._currentPage != null &&
      this._currentPage != undefined &&
      this._currentPage.leavePage != null &&
      this._currentPage.leavePage != undefined
    ) {
      this._currentPage.leavePage();
    }
    if (nextPageData.routeData == null) {
      nextPageData.routeData = {};
    }
    nextPageData.routeData.authorization = this._dataManager.callMethod(
      Constants.MODULE_TYPE.LOGIN,
      "getAutorization"
    );
    nextPageData.routeData.userData = this._dataManager.callMethod(
      Constants.MODULE_TYPE.USER,
      "getSelfData"
    );

    //假如以前存在相同的route
    if (nextIndex > -1) {
      nextPageData.routeData.isBack = isBack;
      currentRoutes[nextIndex].pageData = nextPageData;
      this._navigator.jumpTo(currentRoutes[nextIndex]);
      nextPageData.enterPage && nextPageData.enterPage();
    } else {
      nextPageData.routeData.isBack = false;
      this._pushPage(nextPageData);
    }
    if (this._pageIDQueue.length > 0) {
      let prePageData = null;
      if (this._pageIDQueue.length == 1) {
        nextPageData = this._copyPageData(Config.pages.home);
        if (prePageData) {
          prePageData.routeID = ++this._routeID;
        }
      } else {
        prePageData = this._pageIDQueue[this._pageIDQueue.length - 2];
      }
      nextPageData.prePageData = prePageData;
    }
    this.setCurrentPage(nextPageData);
    // console.log("pageIDQueue", this._pageIDQueue);
  }

  _copyPageData(pageData) {
    var routeData = pageData.routeData;
    pageData.routeData = null;
    var copyPageData = ObjUtils.copy(pageData);
    copyPageData.routeData = routeData;
    return copyPageData;
  }
}

new Routes();
// module.exports = instance;
const routes = instance;
export default routes;
